<template>
  <div>
    <el-card>
      <div slot="header">
        <div class="category-header">
          <span>销售额类别占比</span>
          <el-radio-group size="small" v-model="value">
            <el-radio-button label="全部渠道"></el-radio-button>
            <el-radio-button label="线上"></el-radio-button>
            <el-radio-button label="门店"></el-radio-button>
          </el-radio-group>
        </div>

      </div>
              <div class="charts" ref="charts"></div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  mounted () {
    let mycharts = echarts.init(this.$refs.charts)
    mycharts.setOption({
        title:{
            text:'',
            subtext:'',
            left:'center',
            top:'center',
        },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        top: '5%',
        left: 'center'
      },
      series: [
        {
        top:'10%',
          name: '销售额类别占比',
          type: 'pie',
          radius: ['40%', '70%'],
          avoidLabelOverlap: false,

          label: {
            show: true,
            position: 'outside'
          },
          labelLine: {
            show: true
          },
          data: [
            { value: 1048, name: '视频广告' },
            { value: 735, name: '搜索引擎' },
            { value: 580, name: '联盟广告' },
            { value: 484, name: '邮件营销' },
            { value: 300, name: '直接访问' }
          ]
        }
      ]
    })
    //绑定事件
    mycharts.on('mousemove',(params) => {
        const {name,value} = params.data
        //重新设置标题
        mycharts.setOption({
            title:{
                text:name,
                subtext:value
            }
        })
    });
  },
  data () {
    return {
      value: '全部渠道'
    }
  }
}
</script>

<style scoped>
.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.charts {
  width: 100%;
  height: 300px;
}
</style>